import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../components/Home.vue";
import NewsList from "../components/news/NewsList.vue";
import NewsDetail from "../components/news/NewsDetail.vue";
import PicShare from "../components/picShare/PicShare.vue";
import PicInfo from "../components/picShare/PicInfo.vue";
import Car from "../components/Car.vue";
import Search from "../components/Search.vue";
import GoodsList from "../components/goods/GoodsList.vue";
import GoodsInfo from "../components/goods/GoodsInfo.vue";
import AddGoods from "../components/goods/AddGoods.vue";
import Welcome from "../components/Welcome.vue";
import Goodscontent from "../components/goods/Goodscontent.vue";
import Comment from "../components/comment.vue";

Vue.use(VueRouter);

const routes = [
  { path: "/", redirect: "/welcome" },
  {
    path: "/welcome",
    component: Welcome,
    redirect: "/home",
    children: [
      { path: "/home", component: Home },
      { path: "/newsList", component: NewsList },
      { path: "/newsDetail", component: NewsDetail },
      { path: "/picShare", component: PicShare },
      { path: "/picShare/info", component: PicInfo },
      { path: "/car", component: Car },
      { path: "/search", component: Search },
      { path: "/goodsList", component: GoodsList },
      { path: "/goodsInfo", component: GoodsInfo },
      { path: "/addGoods", component: AddGoods },
      { path: "/goodscontent/:id", component: Goodscontent },
      { path: "/comment", component: Comment }
    ]
  }
];

const router = new VueRouter({
  routes
});

// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  router.app.$options.store.commit("getUrlStr", to.path);
  next();
});
export default router;
